package main

import "fmt"

func main() {
	c := make(chan int)

	go func() {
		for i := 0; i < 5; i++ {
			c <- i
		}
		//close可以关闭一个channel
		close(c)
	}()

	//all goroutines are asleep - deadlock!
	//也会发生死锁 假如不关闭 close(c) 的话
	for data := range c {
		fmt.Println(data)
	}
	fmt.Println("Main Finished..")
}
